package com.edu.exam.enums.academic;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 日历类型枚举
 */
public enum CalendarType implements BaseEnum {
    GREGORIAN("GREGORIAN", "公历"),
    LUNAR("LUNAR", "农历"),
    ACADEMIC("ACADEMIC", "学年历");

    private final String code;
    private final String description;

    CalendarType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static CalendarType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Calendar type code cannot be null or empty");
        }

        for (CalendarType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown CalendarType code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static CalendarType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Calendar type description cannot be null or empty");
        }

        for (CalendarType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown CalendarType description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}